package com.xiaodao.zk.controller;

import com.xiaodao.zk.entity.Jdbc;
import com.xiaodao.zk.service.ZkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName : ZKController
 * @Description : TODO
 * @Author : xiaodao
 * @Date : 2018/11/20  23:40
 * @Version : 1.0
 **/
@RestController
@RequestMapping("/jdbc")
public class ZKController {
    @Autowired
    ZkService zkService;
    @RequestMapping("/createjdbc")
    public Object createJdbc(String path,String username, String password, HttpServletRequest request){
        Jdbc  jdbc= new Jdbc();
        jdbc.setUserName(username);
        jdbc.setPassword(password);
        if(zkService.existPath(path)){
            zkService.writeData(path,jdbc);
        }else{
            zkService.createPersistent(path,jdbc);
        }
       return zkService.readData(path);

    }
}
